// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#ifndef TESTVECTOR_H
#define TESTVECTOR_H

#include <QObject>
#include <QtTest/QtTest>

#include "Vector.h"

class TestVector : public QObject
{
  Q_OBJECT
public:
    explicit TestVector(QObject *parent = 0) : QObject(parent) {}

private:

private slots:
    void testVector() {
        Vector c1, c2;

        // compare two empty vectors
        QCOMPARE(c1.isEmpty(), true);
        QCOMPARE(c2.isEmpty(), true);
        QCOMPARE(c1 == c2, true);
        QCOMPARE(c2 == c1, true);

        c2 = Vector(c1);
        QCOMPARE(c2.isEmpty(), true);

        // compare empty with non empty vector
        c1 = Vector(1.2, 1.3, 1.4);
        QCOMPARE(Vector() == Vector(0,0,0), false);
        QCOMPARE(c1.isEmpty(), false);
        QCOMPARE(c1 == c2, false);
        QCOMPARE(c2 == c1, false);

        c2 = Vector(c1);
        // compare two non-empty vectors
        QCOMPARE(c1 == c2, true);
        QCOMPARE(c2 == c1, true);

        c2.setCoordinates(1.2, 1.3, 1.4);
        QCOMPARE(c1 == c2, true);
        QCOMPARE(c2 == c1, true);
        c2.setCoordinates(1.200000000001, 1.3, 1.4);
        QCOMPARE(c1 == c2, true);
        QCOMPARE(c2 == c1, true);

        c2.setCoordinates(1, 2, 3);
        QCOMPARE(c1 == c2, false);
        QCOMPARE(c2 == c1, false);

        c2.setCoordinates(-1, c1.y(), c1.z());
        QCOMPARE(c1 == c2, false);
        QCOMPARE(c2 == c1, false);

        c2.setCoordinates(c1.x(), -1, c1.z());
        QCOMPARE(c1 == c2, false);
        QCOMPARE(c2 == c1, false);

        c2.setCoordinates(c1.x(), c1.y(), -1);
        QCOMPARE(c1 == c2, false);
        QCOMPARE(c2 == c1, false);

        GLdouble coordinates[3];
        coordinates[0] = 1.2;
        coordinates[1] = 1.3;
        coordinates[2] = 1.4;
        c2.setCoordinates(coordinates);
        QCOMPARE(c1 == c2, true);
        QCOMPARE(c2 == c1, true);

        QCOMPARE(c1.x(), 1.2);
        QCOMPARE(c1.y(), 1.3);
        QCOMPARE(c1.z(), 1.4);

        c1.setX(0.1);
        c1.setY(0.2);
        c1.setZ(0.3);

        const GLdouble *c = c1.getGLCoordinates();
        QCOMPARE(c[0], 0.1);
        QCOMPARE(c[1], 0.2);
        QCOMPARE(c[2], 0.3);
    }

    void testCoordinatesOperations() {
        Vector v1(1.0, 2.0, 3.0);
        Vector v2(-2.0, 4.0, 7.0);

        // Expected values
        Vector resAdd(-1.0, 6.0, 10.0);
        Vector resSub(3.0, -2.0, -4.0);
        double resMulScalar = 27.0;
        Vector resMulVector(2.0, -13.0, 8.0);
        Vector resV1mult(2.3,4.6,6.9);

        // Computed values
        Vector vAdd = v1 + v2;
        Vector vSub = v1 - v2;
        double vMulScalar = v1 * v2;
        Vector vMulVector = v1 ^ v2;
        Vector vMultScal = v1 * 2.3;

        QVERIFY(vAdd == resAdd);
        QVERIFY(vSub == resSub);
        QCOMPARE(v2 - v1, -resSub);
        QCOMPARE(-v2 + (-v1), -resAdd);
        QVERIFY(vMulScalar == resMulScalar);
        QVERIFY(vMulVector == resMulVector);
        QVERIFY(vMultScal == resV1mult);
    }
};

#endif // TESTVECTOR_H
